package cn.schoolwow.workflow.test.module.analyzeWorkReport.audit.single.common;

import cn.schoolwow.quickflow.domain.FlowContext;
import cn.schoolwow.quickflow.flow.BusinessFlow;
import cn.schoolwow.workflow.QuickWorkFlow;
import cn.schoolwow.workflow.domain.instance.WorkFlowInstanceStatus;
import cn.schoolwow.workflow.domain.task.WorkFlowTaskQuery;
import cn.schoolwow.workflow.domain.task.WorkFlowTaskResponse;
import cn.schoolwow.workflow.entity.WorkFlowInstance;
import org.junit.Assert;

import java.util.List;

public class CheckWorkFlowResult implements BusinessFlow {
    @Override
    public void executeBusinessFlow(FlowContext flowContext) throws Exception {
        QuickWorkFlow quickWorkFlow = flowContext.checkInstanceData(QuickWorkFlow.class);
        WorkFlowInstance workFlowInstance = flowContext.checkInstanceData(WorkFlowInstance.class);
        WorkFlowInstanceStatus workFlowInstanceStatus = flowContext.checkInstanceData(WorkFlowInstanceStatus.class);

        flowContext.executeFlowList(new PrintWorkFlowInstanceHistoryFlow());
        //检查实例
        {
            WorkFlowInstance currentWorkFlowInstance = quickWorkFlow.getSingleWorkFlowInstance(workFlowInstance.getId());
            Assert.assertEquals(workFlowInstanceStatus.status, currentWorkFlowInstance.getStatus().intValue());
        }
        //检查任务
        {
            WorkFlowTaskQuery workFlowTaskQuery = new WorkFlowTaskQuery();
            workFlowTaskQuery.instanceIdList.add(workFlowInstance.getId());
            workFlowTaskQuery.complete = false;
            List<WorkFlowTaskResponse> workFlowTaskResponseList = quickWorkFlow.getWorkFlowTaskList(workFlowTaskQuery);
            Assert.assertEquals(0, workFlowTaskResponseList.size());
        }
    }

    @Override
    public String name() {
        return "检查工作流执行结果";
    }
}
